@file:JvmMultifileClass
@file:JvmName("FileTypeCompat")

package hos.kotlin

/**
 * <p>Title: FileExt </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @date : 2025-04-11 16:04
 * @version : 1.0
 */

fun getFileType(fileName: String): FileType {
    if (fileName.includes(".m4a", true) || fileName.includes(
            ".mp3",
            true
        ) || fileName.includes(".wav", true) || fileName.includes(".amr", true)
        || fileName.includes(".aac", true)
    ) {
        return FileType.AUDIO
    }
    if (fileName.includes(".mp4", true) || fileName.includes(".mts", true)) {
        return FileType.VIDEO
    }
    if (fileName.includes(".jpg", true) || fileName.includes(
            ".gif",
            true
        ) || fileName.includes(".jpeg", true) ||
        fileName.includes(".bmp", true)
    ) {
        return FileType.IMAGE
    }
    if (fileName.includes(".xls", true) || fileName.includes(".xlsx", true)) {
        return FileType.EXCEL
    }
    if (fileName.includes(".txt", true)) {
        return FileType.TXT
    }
    if (fileName.includes(".chm", true)) {
        return FileType.CHM
    }
    if (fileName.includes(".docx", true) || fileName.includes(".doc", true)) {
        return FileType.WORD
    }
    if (fileName.includes(".pdf", true)) {
        return FileType.PDF
    }
    if (fileName.includes(".ppt", true)) {
        return FileType.PPT
    }
    if (fileName.includes(".apk", true)) {
        return FileType.APK
    }
    if (fileName.includes(".html", true)) {
        return FileType.HTML
    }
    return FileType.ALL
}

enum class FileType(val type: String, val typeName: String) {
    HTML("text/html", "html"), IMAGE("image/*", "image"),
    PDF("application/pdf", "pdf"),
    TXT("text/plain", "txt"),
    AUDIO("audio/*", "audio"), VIDEO("video/*", "video"),
    CHM("application/x-chm", "chm"),
    WORD("application/msword", "word"), EXCEL("application/vnd.ms-excel", "excel"),
    PPT("application/vnd.ms-powerpoint", "ppt"),
    APK(
        "application/vnd.android.package-archive", "apk"
    ),
    ALL(
        "*/*", "all"
    );

}